package io.noties.markwon.base.html.video


import timber.log.Timber
import io.noties.markwon.base.*
import io.noties.markwon.base.image.*
import io.noties.markwon.base.image.span.AsyncDrawableSpan

class VideoSpanFactory : SpanFactory {
    override fun getSpans(configuration: MarkwonConfiguration, props: RenderProps): Any {
        val posterUrl = ImageProps.DESTINATION.require(props)
        val videoUrl = VideoProps.VIDEO_DESTINATION[props, ""]
        Timber.d("VideoSpanFactory video getSpans videoUrl=%s \t posterUrl=%s", videoUrl, posterUrl)
        val posterDrawable = AsyncDrawable(
            posterUrl,
            configuration.asyncDrawableLoader(),
            configuration.imageSizeResolver(),
            ImageProps.IMAGE_SIZE[props]
        )
        return AsyncVideoDrawableSpan(
            configuration.categoryTheme().currentTheme,
            posterDrawable,
            AsyncDrawableSpan.ALIGN_CENTER,
            ImageProps.REPLACEMENT_TEXT_IS_LINK[props, false],
            videoUrl
        )
    }
}